﻿namespace MicroCloud.Api.Systems.Controllers
{
    [AllowAnonymous]
    [Description("字典")]
    public class DictController : SystemsControllerBase
    {
        protected IDictService DictService => ServiceProvider.GetService<IDictService>();

        /// <summary>
        /// 字典编码获取字典信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("字典编码获取字典信息")]
        public AjaxResult GetDicts(string code)
        {
            var dictEntries = DictService.Dicts
                .FirstOrDefault(a => a.Code == code)?.DictEntrys.OrderBy(a => a.OrderNo).Select(a => new
                {
                    a.Id,
                    a.CodeName,
                    a.CodeValue,
                    a.Remark
                });

            return AjaxResult.Success(dictEntries);
        }

    }
}